home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / InterLaunch 1.1.1 / src / main.c < prev    next >
Encoding:
Text File  |  1995-12-28  |  11.2 KB  |  365 lines  |  [TEXT/CWIE]

  1. /* ----------------------------------------------------------------------
  2.  
  3.     Launcher
  4.     
  5.     Written by: Paul Celestin
  6.     
  7.     950314 - work begins on the project
  8.     950321 - work continues
  9.     950808 - added ability to open ConfigPPP
  10.     951213 - fixed (maybe) crashing bug when launching apps
  11.  
  12. ---------------------------------------------------------------------- */
  13.  
  14.  
  15. /* ----------------------------------------------------------------------
  16. includes
  17. ---------------------------------------------------------------------- */
  18.  
  19. #include    "the_defines.h"
  20. #include    "the_globals.h"
  21. #include    "the_prototypes.h"
  22. #include    "pppcontrol.h"
  23.  
  24. Boolean                gDone,
  25.                     gWNEImplemented,
  26.                     gInBackground;
  27. int                    gNumApps;
  28. EventRecord            gTheEvent;
  29. MenuHandle            gAppleMenu,
  30.                     gFileMenu;
  31. WindowPtr            gTheWindow;
  32. PixPatHandle        gPixPat;
  33. ProcessSerialNumber    gMailApp,
  34.                     gNewsApp,
  35.                     gFTPApp,
  36.                     gWebApp,
  37.                     gTelnetApp;
  38.  
  39. /* ----------------------------------------------------------------------
  40. main - here is where it all began...
  41. ---------------------------------------------------------------------- */
  42. void main()
  43. {
  44.     InitToolBox();
  45.     InitMenuBar();
  46.     MainLoop();
  47.     ExitToShell();
  48. }
  49.  
  50.  
  51. /* ----------------------------------------------------------------------
  52. InitToolBox
  53. ---------------------------------------------------------------------- */
  54. void InitToolBox()
  55. {
  56.     InitGraf(&qd.thePort);
  57.     InitFonts();
  58.     FlushEvents(everyEvent, 0);
  59.     InitWindows();
  60.     InitMenus();
  61.     TEInit();
  62.     InitDialogs(0L);
  63.     InitCursor();
  64. }
  65.  
  66.  
  67. /* ----------------------------------------------------------------------
  68. InitMenuBar
  69. ---------------------------------------------------------------------- */
  70. void InitMenuBar()
  71. {
  72.     Handle    myMenuBar;
  73.     
  74.     myMenuBar = GetNewMBar(MENU_BASE_ID);
  75.     if (myMenuBar == NIL)
  76.         SysBeep(1);
  77.     else
  78.         SetMenuBar(myMenuBar);
  79.     
  80.     gAppleMenu = GetMHandle(MENU_APPLE_ID);
  81.     if (gAppleMenu == NIL)
  82.         SysBeep(1);
  83.     else
  84.         AddResMenu(gAppleMenu,'DRVR');
  85.     
  86.     gFileMenu = GetMHandle(MENU_FILE_ID);
  87.     if (gFileMenu == NIL)
  88.         SysBeep(1);
  89.  
  90.     DrawMenuBar();
  91. }
  92.  
  93.  
  94. /* ----------------------------------------------------------------------
  95. MainLoop
  96. ---------------------------------------------------------------------- */
  97. void MainLoop()
  98. {
  99.     RgnHandle        cursorRgn;
  100.     Boolean            gotEvent;
  101.     WindowRecord    *myWinRecord;
  102.     Rect            myWinRect;
  103.     Str255             myTitle;
  104.     
  105.     gInBackground = false;
  106.     
  107.     cursorRgn = NewRgn();
  108.     
  109.     gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM,ToolTrap) !=
  110.         NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap));
  111.  
  112.     gPixPat = GetPixPat(SYSTEM_PPAT);
  113.  
  114.     myWinRect = qd.screenBits.bounds;
  115.     myWinRecord = NIL;
  116.     gTheWindow =
  117.         NewCWindow(myWinRecord,&myWinRect,"\p",FALSE,plainDBox,(WindowPtr)-1L,FALSE,0L);
  118.     
  119.     if (gTheWindow)
  120.     {
  121.         DrawButtons();
  122.         ShowWindow(gTheWindow);
  123.         DoUpdate();
  124.  
  125.         gDone = false;
  126.  
  127.         while (gDone == false)
  128.         {
  129.             if (gWNEImplemented)
  130.                 gotEvent = WaitNextEvent(everyEvent,&gTheEvent,MIN_SLEEP,cursorRgn);
  131.             else
  132.             {
  133.                 SystemTask();
  134.                 gotEvent = GetNextEvent(everyEvent,&gTheEvent);
  135.             }
  136.         
  137.             if (gotEvent)
  138.                 Do();
  139.         }
  140.         QuitAllApps();
  141.     }
  142. }
  143.  
  144.  
  145. /* ------------------------------------------------enuChoice);
  146.             break;
  147.         case inSysWindow:
  148.             SystemClick(&gTheEvent,window);
  149.             break;
  150.         case inContent:
  151.             if (window != FrontWindow())
  152.                 SelectWindow(window);
  153.             else
  154.             {
  155.                 p = gTheEvent.where;
  156.                 GlobalToLocal(&p);
  157.                 DoWindow(p);
  158.             }
  159.             break;
  160.         default:
  161.             break;
  162.     }
  163. }
  164.  
  165. /* ----------------------------------------------------------------------
  166. DoMenu
  167. ---------------------------------------------------------------------- */
  168. void DoMenu(menuChoice)
  169. long int menuChoice;
  170. {
  171.     int    theMenu;
  172.     int    theItem;
  173.     
  174.     if (menuChoice != 0)
  175.     {
  176.         theMenu = HiWord(menuChoice);
  177.         theItem = LoWord(menuChoice);
  178.         switch (theMenu)
  179.         {
  180.             case MENU_APPLE_ID:
  181.                 DoMenuApple(theItem);
  182.                 break;
  183.             case MENU_FILE_ID:
  184.                 DoMenuFile(theItem);
  185.                 break;
  186.             default:
  187.                 break;
  188.         }
  189.         HiliteMenu(0);
  190.     }
  191. }
  192.  
  193. /* ----------------------------------------------------------------------
  194. DoWindow
  195. ---------------------------------------------------------------------- */
  196. void DoWindow(Point p)
  197. {
  198.     short            choice;
  199.     ControlHandle    control;
  200.     CursHandle        theCursor;
  201.     
  202.     if (FindControl(p,gTheWindow,&control))
  203.     {
  204.         if (TrackControl(control,p,NIL))
  205.         {
  206.             theCursor = GetCursor(4);
  207.             HLock((Handle)theCursor);
  208.             SetCursor(*theCursor);
  209.             HUnlock((Handle)theCursor);
  210.  
  211.             choice = GetCtlValue(control);
  212.             
  213.             switch (choice)
  214.             {
  215.                 case PPP_CONTROL:
  216.                     DoPPP();
  217.                     break;
  218.                 case MAIL_CONTROL:
  219.                     DoMail();
  220.                     break;
  221.                 case NEWS_CONTROL:
  222.                     DoNews();
  223.                     break;
  224.                 case FTP_CONTROL:
  225.                     DoFTP();
  226.                     break;
  227.                 case WEB_CONTROL:
  228.                     DoWeb();
  229.                     break;
  230.                 case TELNET_CONTROL:
  231.                     DoTelnet();
  232.                     break;
  233.                 default:
  234.                     break;
  235.             }
  236.         }
  237.     }
  238. }
  239.  
  240.  
  241. /* ----------------------------------------------------------------------
  242. DoPPP
  243. ---------------------------------------------------------------------- */
  244. void DoPPP()
  245. {
  246.     short    vRefNum;
  247.     long    dirID;
  248.     FSSpec    theApp;
  249.     OSErr    myErr;
  250.  
  251.     myErr = FindFolder(kOnSystemDisk, kControlPanelFolderType,
  252.         kDontCreateFolder, &vRefNum, &dirID);
  253.     if (myErr != noErr)
  254.     {
  255.         SysBeep(1);
  256.         return;
  257.     }
  258.     myErr = LocateFile(TYPE_CDEV, CREATOR_PPP, vRefNum, &theApp);
  259.     if (myErr != noErr)
  260.     {
  261.         SysBeep(1);
  262.         return;
  263.     }
  264.     myErr = OpenCP(theApp, CREATOR_PPP);
  265.     if (myErr != noErr)
  266.     {
  267.         SysBeep(1);
  268.         return;
  269.     }
  270. }
  271.  
  272.  
  273. /* ----------------------------------------------------------------------
  274. DoMail
  275. ---------------------------------------------------------------------- */
  276. void DoMail()
  277. {
  278.     FSSpec    theApp;
  279.  
  280.     if (LocateFile('APPL', CREATOR_MAIL, 0, &theApp) == noErr)
  281.         if (LaunchIt(theApp,&gMailApp) != noErr)
  282.             SysBeep(1);
  283. }
  284.  
  285.  
  286. /* ----------------------------------------------------------------------
  287. DoNews
  288. ---------------------------------------------------------------------- */
  289. void DoNews()
  290. {
  291.     FSSpec    theApp;
  292.  
  293.     if (!pppup())
  294.         pppopen();
  295.     if (LocateFile('APPL', CREATOR_NEWS, 0, &theApp) == noErr)
  296.         if (LaunchIt(theApp,&gNewsApp) != noErr)
  297.             SysBeep(1);
  298. }
  299.  
  300.  
  301. /* ----------------------------------------------------------------------
  302. DoFTP
  303. ---------------------------------------------------------------------- */
  304. void DoFTP()
  305. {
  306.     FSSpec    theApp;
  307.  
  308.     if (!pppup())
  309.         pppopen();
  310.     if (LocateFile('APPL', CREATOR_FTP, 0, &theApp) == noErr)
  311.         if (LaunchIt(theApp,&gFTPApp) != noErr)
  312.             SysBeep(1);
  313. }
  314.  
  315.  
  316. /* ----------------------------------------------------------------------
  317. DoWeb
  318. ---------------------------------------------------------------------- */
  319. void DoWeb()
  320. {
  321.     FSSpec    theApp;
  322.  
  323.     if (!pppup())
  324.         pppopen();
  325.     if (LocateFile('APPL', CREATOR_WEB, 0, &theApp) == noErr)
  326.         if (LaunchIt(theApp,&gWebApp) != noErr)
  327.             SysBeep(1);
  328. }
  329.  
  330.  
  331. /* ----------------------------------------------------------------------
  332. DoTelnet
  333. ---------------------------------------------------------------------- */
  334. void DoTelnet()
  335. {
  336.     FSSpec    theApp;
  337.  
  338.     if (!pppup())
  339.         pppopen();
  340.     if (LocateFile('APPL', CREATOR_TELNET, 0, &theApp) == noErr)
  341.         if (LaunchIt(theApp,&gTelnetApp) != noErr)
  342.             SysBeep(1);
  343. }
  344.  
  345.  
  346. /* ----------------------------------------------------------------------
  347. QuitAllApps
  348. ---------------------------------------------------------------------- */
  349. void QuitAllApps()
  350. {
  351.     CursHandle        theCursor;
  352.  
  353.     theCursor = GetCursor(4);
  354.     HLock((Handle)theCursor);
  355.     SetCursor(*theCursor);
  356.     HUnlock((Handle)theCursor);
  357.  
  358.     QuitIt(&gMailApp);
  359.     QuitIt(&gNewsApp);
  360.     QuitIt(&gFTPApp);
  361.     QuitIt(&gWebApp);
  362.     QuitIt(&gTelnetApp);
  363.     if (pppup())
  364.         pppclose(1);
  365. }